package context;

import context.bfpp.ConfigCenterBFPP;
import context.bfpp.CustomerBFPP;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

public class CustomerClassPathXmlApplicationContext extends ClassPathXmlApplicationContext {

	public CustomerClassPathXmlApplicationContext(String configLocation) throws BeansException {
		super(configLocation);
	}

	@Override
	protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
		super.setAllowCircularReferences(false);
		super.setAllowBeanDefinitionOverriding(false);
		super.customizeBeanFactory(beanFactory);
		super.addBeanFactoryPostProcessor(new CustomerBFPP());
		ConfigurableEnvironment environment = super.getEnvironment();
		//String[] configLocations = super.getConfigLocations();
		//Resource resource = super.getResource(configLocations[0]);
		//Resource[] configResources = super.getConfigResources();
		ConfigCenterBFPP configCenterBFPP = new ConfigCenterBFPP();
		//configCenterBFPP.setLocations(resource);
		//configCenterBFPP.setEnvironment(environment);
		// 此时getBeanFactory拿到的是一个空的BeanFactory,所有不能这样写
		//super.addBeanFactoryPostProcessor(getBean(ConfigCenterBFPP.class));
	}

	@Override
	protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
		System.out.println(">>>自定义application对postProcessBeanFactory扩展 >>> ");
	}
}
